package com.xyht.medicine_management_system.modules.manufacturer.controller;


import com.xyht.medicine_management_system.auth.annotation.TestAnnotation;
import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.annotation.RequestPass;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.manufacturer.entity.req.MmsManufacturerReq;
import com.xyht.medicine_management_system.modules.manufacturer.service.MmsManufacturerService;
import com.xyht.medicine_management_system.modules.medicineSource.entity.req.MmsMedicineSourceReq;
import com.xyht.medicine_management_system.modules.medicineSource.service.MmsMedicineSourceService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 厂家管理 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-11-29
 */
@RestController
@SecretBody
@RequestMapping("/manufacturer")
public class MmsManufacturerController {
    @Resource
    private MmsManufacturerService mmsManufacturerService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @PostMapping("/add")
    @ApiModelProperty(value = "厂家添加")
    public ResponseResult addManufacturer(@RequestBody MmsManufacturerReq sourceReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsManufacturerService.addManufacturer(sourceReq, user_id);
    }

    @GetMapping("/detail")
    @ApiModelProperty(value = "厂家详情")
    @TestAnnotation
    @RequestPass
    public ResponseResult getManufactureDetail(@RequestParam("id") String id) {
        return mmsManufacturerService.getManufactureDetail(id);
    }

    @GetMapping("/list")
    @ApiModelProperty(value = "厂家列表")
    public ResponseResult getMedicineSourceList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                @RequestParam("searchStr") String searchStr) {
        return mmsManufacturerService.getManufactureList(pageNum, pageSize, searchStr);
    }


    @PostMapping("/update")
    @ApiModelProperty(value = "厂家修改")
    public ResponseResult updateManufacture(@RequestBody MmsManufacturerReq sourceReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsManufacturerService.updateManufacture(sourceReq, user_id);
    }

    @PostMapping("/delete")
    @ApiModelProperty(value = "厂家删除")
    public ResponseResult deleteManufacture(@RequestBody MmsManufacturerReq sourceReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsManufacturerService.deleteManufacture(sourceReq, user_id);
    }

}

